/*************************************************
Author: byron
Date: 12/10/2012
Description:
Notes: 
*************************************************/

#ifndef __CStatusCfg_h__
#define __CStatusCfg_h__

#include "commclass.h"
#include "CTArray.h"
#include "CTHashObjectMgr.h"

class CStatusCfgData
{
public:
    CStatusCfgData() 
    {
        Clear();
    }

    void Clear()
    {
        _chType = 0;
        _iResID = 0;
        _iActType = 0;
        _iAddMax = 0;
        _iTriggerWay = 0;
        _iAppearType = 0;
        _iTriggerRate = 0;
        _iTriggerTime = 0;
        _iValueType = 0;
        _iData = 0;
        _iAuxData = 0;
        _uiSkillEffectID = 0;
        _uiSkillAffectID = 0;
        _uiBufferID = 0;

        _auiAffectID.Clear();
        _auiSkillID.Clear();
    }

    virtual ~CStatusCfgData() 
    {
    }

    bool IsValidID() const {return _iResID > 0;}
    char GetType() const {return _chType;}
    int GetTriggerWay() const {return _iTriggerWay;}
    int GetAppearType() const {return _iAppearType;}
    int GetTriggerRate() const {return _iTriggerRate;}
    int GetTriggerTime() const {return _iTriggerTime;}
    int GetActType() const {return _iActType;}
    int GetResID() const {return _iResID;}
    int GetSkillIDSize() const {return _auiSkillID.Size();}
    int GetAffectIDSize() const {return _auiAffectID.Size();}
    int GetValueType() const {return _iValueType;}
    int GetAddMax() const {return _iAddMax;}
    int GetData() const {return _iData;}
    int GetAuxData() const {return _iAuxData;}
    unsigned int GetSkillEffect() const {return _uiSkillEffectID;}
    unsigned int GetSkillAffect() const {return _uiSkillAffectID;}
    unsigned int GetBufferID() const {return _uiBufferID;}

    unsigned int GetAffectID(int iIndex)
    {
        if (iIndex >= 0 && iIndex < _auiAffectID.Size())
        {
            return _auiAffectID[iIndex];
        }

        return 0;
    }

    unsigned int GetSkillID(int iIndex)
    {
        if (iIndex >= 0 && iIndex < _auiSkillID.Size())
        {
            return _auiSkillID[iIndex];
        }

        return 0;
    }

    void SetType(char chType){_chType = chType;}
    void SetActType(int iActType){_iActType = iActType;}
    void SetResID(int iResID){_iResID = iResID;}
    void SetTriggerWay(int iTriggerWay){_iTriggerWay = iTriggerWay;}
    void SetAppearType(int iAppearType){_iAppearType = iAppearType;}
    void SetTriggerRate(int iTriggerRate){_iTriggerRate = iTriggerRate;}
    void SetTriggerTime(int iVal){_iTriggerTime = iVal;}
    void SetAddMax(int iAddMax){_iAddMax = iAddMax;}
    void SetValueType(int iValueType){_iValueType = iValueType;}
    void SetData(int iData){_iData = iData;}
    void SetAuxData(int iAuxData){_iAuxData = iAuxData;}
    void SetSkillEffect(unsigned int uiSkillEffectID)
    {
        _uiSkillEffectID = uiSkillEffectID;
    }
    void SetSkillAffect(unsigned int uiSkillAffectID)
    {
        _uiSkillAffectID = uiSkillAffectID;
    }
    void SetBufferID(unsigned int uiVal)
    {
        _uiBufferID = uiVal;
    }

    void AddAffectID(unsigned int uiAffectID)
    {
        _auiAffectID.AddOneItem(uiAffectID);
    }
    void AddSkillID(unsigned int uiSkillID){_auiSkillID.AddOneItem(uiSkillID);}

private:
    char                _chType;            //类型(0:离线消失 1:自然时间消失 2:绝对时间消失 3:永久类型比如能力)
    int                 _iResID;            //配置ID
    int                 _iActType;          //生效活动类型
    int                 _iAddMax;           //叠加上限
    int                 _iTriggerWay;       //触发方式
    int                 _iAppearType;       //提示方式
    int                 _iTriggerRate;      //生效机率 千分比
    int                 _iTriggerTime;      //生效次数限制
    int                 _iValueType;
    int                 _iData;
    int                 _iAuxData;
    unsigned int        _uiSkillEffectID;   //技能特效
    unsigned int        _uiSkillAffectID;   //功能效果
    unsigned int        _uiBufferID;        //用于前端展示的特效图标ID

    CTLib::CTArray<unsigned int, MAX_STATUS_SKILL_AFF_COUNT> _auiAffectID;
    CTLib::CTArray<unsigned int, MAX_STATUS_SKILL_COUNT> _auiSkillID;
};

class CStatusGroup
{
public:
    CStatusGroup() 
    {
        Clear();
    }

    void Clear()
    {
        _iResID = 0;
        _aiStatusID.Clear();
    }

    virtual ~CStatusGroup() 
    {
    }

    bool IsValidID() const {return _iResID > 0;}

    int GetResID() const {return _iResID;}

    int GetStatusIDSize()
    {
        return _aiStatusID.Size();
    }

    int GetStatusID(int iIndex)
    {
        if (iIndex >= 0 && iIndex < _aiStatusID.Size())
        {
            return _aiStatusID[iIndex];
        }

        return 0;
    }

    void SetResID(int iResID){_iResID = iResID;}
    void AddStatusID(int iStatusID){_aiStatusID.AddOneItem(iStatusID);}

private:
    int     _iResID;
    CTLib::CTArray<int, MAX_STATUS_GROUP_COUNT> _aiStatusID;
};

class CStatusCfg
{
public:
    typedef CTLib::CTHashObjectMgr<int, CStatusCfgData> T_STATUS_CFG_HASH;
    typedef CTLib::CTHashObjectMgr<int, CStatusGroup> T_STATUS_GROUP_HASH;

    CStatusCfg() 
    {
    }

    virtual ~CStatusCfg() 
    {
    }

    static int CountSize()
    {
        return T_STATUS_CFG_HASH::CountSize(MAX_STATUS_CONFIG_COUNT) +
               T_STATUS_GROUP_HASH::CountSize(MAX_STATUS_GROUP_CFG_COUNT);
    }

    int Init(const char* sBuff)
    {
        int iRet = 0;
        int iOffSet = 0;

        iRet = _stStatusCfgHash.Init(sBuff+iOffSet, MAX_STATUS_CONFIG_COUNT);
        CT_RETURN(iRet);
        iOffSet += T_STATUS_CFG_HASH::CountSize(MAX_STATUS_CONFIG_COUNT);

        iRet = 
            _stStatusGroupHash.Init(sBuff+iOffSet, MAX_STATUS_GROUP_CFG_COUNT);
        CT_RETURN(iRet);
        iOffSet += T_STATUS_GROUP_HASH::CountSize(MAX_STATUS_GROUP_CFG_COUNT);

        return 0;
    }

    int AddConfig(CStatusCfgData& stCfgData);

    int FindConfig(int iResID);

    CStatusCfgData& GetConfig(int iIndex);

    int AddGroupConfig(CStatusGroup& stGroupData);

    int FindGroupConfig(int iGroupID);

    CStatusGroup& GetGroupConfig(int iIndex);

private:
     T_STATUS_CFG_HASH _stStatusCfgHash;
     T_STATUS_GROUP_HASH _stStatusGroupHash;
};

#endif // __CStatusCfg_h__

